package jehc.djshi.oauth.service.impl;
import java.util.List;
import java.util.Map;

import jehc.djshi.oauth.service.OauthResourcesService;
import jehc.djshi.common.base.BaseService;
import jehc.djshi.common.util.ExceptionUtil;
import jehc.djshi.oauth.dao.OauthResourcesDao;
import jehc.djshi.oauth.model.OauthResources;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import jehc.djshi.oauth.dao.OauthResourcesDao;
import jehc.djshi.oauth.model.OauthResources;

/**
 * @Desc 授权中心资源中心
 * @Author 邓纯杰
 * @CreateTime 2012-12-12 12:12:12
 */
@Service("oauthResourcesService")
public class OauthResourcesServiceImpl extends BaseService implements OauthResourcesService {
	@Autowired
	private OauthResourcesDao oauthResourcesDao;
	/**
	* 分页
	* @param condition 
	* @return
	*/
	public List<OauthResources> getOauthResourcesListByCondition(Map<String,Object> condition){
		try{
			return oauthResourcesDao.getOauthResourcesListByCondition(condition);
		} catch (Exception e) {
			/**捕捉异常并回滚**/
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
	}
	/**
	* 查询对象
	* @param resources_id 
	* @return
	*/
	public OauthResources getOauthResourcesById(String resources_id){
		try{
			OauthResources oauthResources = oauthResourcesDao.getOauthResourcesById(resources_id);
			return oauthResources;
		} catch (Exception e) {
			/**捕捉异常并回滚**/
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
	}
	/**
	* 添加
	* @param oauthResources 
	* @return
	*/
	public int addOauthResources(OauthResources oauthResources){
		int i = 0;
		try {
			oauthResources.setCreate_id(getXtUid());
			oauthResources.setCreate_time(getDate());
			i = oauthResourcesDao.addOauthResources(oauthResources);
		} catch (Exception e) {
			i = 0;
			/**捕捉异常并回滚**/
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
		return i;
	}
	/**
	* 修改
	* @param oauthResources 
	* @return
	*/
	public int updateOauthResources(OauthResources oauthResources){
		int i = 0;
		try {
			oauthResources.setUpdate_id(getXtUid());
			oauthResources.setUpdate_time(getDate());
			i = oauthResourcesDao.updateOauthResources(oauthResources);
		} catch (Exception e) {
			i = 0;
			/**捕捉异常并回滚**/
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
		return i;
	}
	/**
	* 修改（根据动态条件）
	* @param oauthResources 
	* @return
	*/
	public int updateOauthResourcesBySelective(OauthResources oauthResources){
		int i = 0;
		try {
			oauthResources.setUpdate_id(getXtUid());
			oauthResources.setUpdate_time(getDate());
			i = oauthResourcesDao.updateOauthResourcesBySelective(oauthResources);
		} catch (Exception e) {
			i = 0;
			/**捕捉异常并回滚**/
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
		return i;
	}
	/**
	* 删除
	* @param condition 
	* @return
	*/
	public int delOauthResources(Map<String,Object> condition){
		int i = 0;
		try {
			i = oauthResourcesDao.delOauthResources(condition);
		} catch (Exception e) {
			i = 0;
			/**捕捉异常并回滚**/
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
		return i;
	}
	/**
	* 批量修改
	* @param oauthResourcesList 
	* @return
	*/
	public int updateBatchOauthResources(List<OauthResources> oauthResourcesList){
		int i = 0;
		try {
			i = oauthResourcesDao.updateBatchOauthResources(oauthResourcesList);
		} catch (Exception e) {
			i = 0;
			/**捕捉异常并回滚**/
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
		return i;
	}
	/**
	* 批量修改（根据动态条件）
	* @param oauthResourcesList 
	* @return
	*/
	public int updateBatchOauthResourcesBySelective(List<OauthResources> oauthResourcesList){
		int i = 0;
		try {
			i = oauthResourcesDao.updateBatchOauthResourcesBySelective(oauthResourcesList);
		} catch (Exception e) {
			i = 0;
			/**捕捉异常并回滚**/
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
		return i;
	}

	/**
	 * 根据Role查资源
	 * @param condition
	 * @return
	 */
	public List<OauthResources> getResourcesListForRole(Map<String, Object> condition){
		return oauthResourcesDao.getResourcesListForRole(condition);
	}

	/**
	 * 获取全部资源
	 * @param condition
	 * @return
	 */
	public List<OauthResources> getOauthResourcesListAll(Map<String, Object> condition){
		return oauthResourcesDao.getOauthResourcesListAll(condition);
	}
}
